package cn.edu.nwpu.warehousemanagement.util;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 自增工具类，每天凌晨0点归0 后续从配置文件读取时间 todo
 *
 * @author Loadstar
 * @version 1.0
 */
@Component
public class IncrementUtil {
    private static final AtomicLong increment = new AtomicLong(0);

    // increment++ 并返回新值
    public static long getIncrement() {
        return increment.incrementAndGet();
    }

    private static void setIncrement(long number) {
        increment.set(number);
    }

    @Scheduled(cron = "0 0 0 * * ?") // 每天0点
    public static void returnZero() { // 无需 synchronized
        setIncrement(0);
    }
}
